/*
 * cert.c
 *
 *  Created on: Feb 11, 2012
 *      Author: jiabin
 */

#include "cert.h"
#include <openssl/pem.h>

void get_subject_CN(X509 *cert, unsigned char **buf)
{
	X509_NAME *name = X509_get_subject_name(cert);
	int index = X509_NAME_get_index_by_NID(name, NID_commonName, -1);
	X509_NAME_ENTRY *entry = X509_NAME_get_entry(name, index);

    ASN1_STRING *str = X509_NAME_ENTRY_get_data(entry);

    ASN1_STRING_to_UTF8(&buf, str);
}
